﻿<Window x:Class="Animator3D.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:loc="clr-namespace:Animator3D"
		xmlns:sa="clr-namespace:SkeletalAnimation3D;assembly=SkeletalAnimation3D"
		xmlns:sac="clr-namespace:SkeletalAnimation3D.Core;assembly=SkeletalAnimation3D"
		xmlns:c="clr-namespace:Animator3D.Controls;assembly=Animator3D.Controls"
    Title="Animator3D" Height="600" Width="800" Loaded="MainWindow_Loaded"
		Background="{DynamicResource DarkBrush}" WindowState="Maximized">
	<Grid>
		<Grid x:Name="Container">
            
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
				<ColumnDefinition Width="5"/>
				<ColumnDefinition Width="240" MinWidth="240"/>
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height="*"/>
				<RowDefinition Height="auto"/>
			</Grid.RowDefinitions>
			<StackPanel  Grid.Column="0" Grid.Row="0" Orientation="Vertical" Background="{DynamicResource BaseVerticalGradient}">
				<Button x:Name="NewDocumentButton" Click="NewDocumentButton_Click" Style="{StaticResource NewButton}"/>
				<Button x:Name="OpenDocumentButton" Click="OpenDocumentButton_Click"  Style="{StaticResource OpenButton}"/>
				<Button Style="{StaticResource SaveButton}"/>
				<Button Style="{StaticResource OptionsButton}"/>
				<Button Style="{StaticResource HelpButton}"/>
			</StackPanel>
			<GridSplitter ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2" Style="{StaticResource VerticalGridSplitter}"/>
            <Grid x:Name="KeyframeEditor" Grid.Column="1" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" MinWidth="25"/>
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition Width="*" MinWidth="25"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition MinHeight="25"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition MinHeight="25"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <GridSplitter ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Grid.Column="1" Grid.RowSpan="3" Style="{StaticResource VerticalGridSplitter}"/>
                <GridSplitter ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Style="{StaticResource HorizontalGridSplitter}"/>
                <c:Viewport2D MouseWheel="viewport2D_MouseWheel" MouseDown="viewport2D_MouseDown" MouseMove="viewport2D_MouseMove" MouseUp="viewport2D_MouseUp" Grid.Column="0" Grid.Row="0" x:Name="viewport2DTopLeftKeyframe" Background="Silver" CameraPosition="3,1,0" CameraOrientation="Front" CameraWidth="25"  MinimalUnitsBetweenGridLines="8" MinorGridSize="0.2" MajorGridSize="1.0" MinorGridColor="#33000000" MajorGridColor="#55000000" AxisColor="Red" SelectedBone="{Binding SelectedBoneId, Mode=OneWay}" SelectedPointIds="{Binding SelectedPointIds, Mode=OneWay}" ShowAttachedPoints="{Binding ShowAttachedPoints, Mode=OneWay}" WireFrame="{Binding AnimatedMeshPoints, Mode=OneWay}"  />
                <c:Viewport2D MouseWheel="viewport2D_MouseWheel" MouseDown="viewport2D_MouseDown" MouseMove="viewport2D_MouseMove" MouseUp="viewport2D_MouseUp" Grid.Column="2" Grid.Row="0" x:Name="viewport2DTopRightKeyframe" Background="Silver" CameraPosition="0,1,3" CameraOrientation="Left" CameraWidth="25" MinimalUnitsBetweenGridLines="8" MinorGridSize="0.2" MajorGridSize="1.0" MinorGridColor="#33000000" MajorGridColor="#55000000" AxisColor="Red" SelectedBone="{Binding SelectedBoneId, Mode=OneWay}" SelectedPointIds="{Binding SelectedPointIds, Mode=OneWay}" ShowAttachedPoints="{Binding ShowAttachedPoints, Mode=OneWay}" WireFrame="{Binding AnimatedMeshPoints, Mode=OneWay}"  />
                <c:Viewport2D MouseWheel="viewport2D_MouseWheel" MouseDown="viewport2D_MouseDown" MouseMove="viewport2D_MouseMove" MouseUp="viewport2D_MouseUp" Grid.Column="0" Grid.Row="2" x:Name="viewport2DBottomLeftKeyframe" Background="Silver" CameraPosition="1,0,3" CameraOrientation="Top" CameraWidth="25" MinimalUnitsBetweenGridLines="8" MinorGridSize="0.2" MajorGridSize="1.0" MinorGridColor="#33000000" MajorGridColor="#55000000" AxisColor="Red" SelectedBone="{Binding SelectedBoneId, Mode=OneWay}" SelectedPointIds="{Binding SelectedPointIds, Mode=OneWay}" ShowAttachedPoints="{Binding ShowAttachedPoints, Mode=OneWay}" WireFrame="{Binding AnimatedMeshPoints, Mode=OneWay}"  />
                <Grid Grid.Column="2" Grid.Row="2" Background="Black">
                    <Viewport3D x:Name="viewport3DKeyFrame" ClipToBounds="True">
                        <Viewport3D.Camera>
                            <PerspectiveCamera
						Position="0,0,50"
						LookDirection="0,0,-1"
						UpDirection="0,1,0"
						NearPlaneDistance="0.1"
						FarPlaneDistance="100"
						FieldOfView="60">
                                <PerspectiveCamera.Transform>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D Axis="0,1,0" Angle="45"/>
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                </PerspectiveCamera.Transform>
                            </PerspectiveCamera>
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <Model3DGroup >
                                    <AmbientLight Color="#FF333333" />
                                    <PointLight Color="White" Position="30,30,30" Range="50"/>
                                    <Model3DGroup>
                                        <GeometryModel3D x:Name="displayModelKeyframe" />
                                    </Model3DGroup>
                                </Model3DGroup>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
                </Grid>
                <c:AnimationSlider x:Name="TimeSlider" ValueChanged="TimeSlider_ValueChanged" Background="{DynamicResource BaseVerticalGradient}" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" />
            </Grid>
            <Grid x:Name="PoseEditor" Grid.Column="1" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" MinWidth="25"/>
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition Width="*" MinWidth="25"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition MinHeight="25"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition MinHeight="25"/>
                </Grid.RowDefinitions>
                <GridSplitter ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Grid.Column="1" Grid.RowSpan="3" Style="{StaticResource VerticalGridSplitter}"/>
                <GridSplitter ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Style="{StaticResource HorizontalGridSplitter}"/>
                <c:Viewport2D MouseWheel="viewport2D_MouseWheel" MouseDown="viewport2D_MouseDown" MouseMove="viewport2D_MouseMove" MouseUp="viewport2D_MouseUp" Grid.Column="0" Grid.Row="0" x:Name="viewport2DTopLeftPose" Background="Silver" CameraPosition="3,1,0" CameraOrientation="Front" CameraWidth="25"  MinimalUnitsBetweenGridLines="8" MinorGridSize="0.2" MajorGridSize="1.0" MinorGridColor="#33000000" MajorGridColor="#55000000" AxisColor="Red" SelectedBone="{Binding SelectedBoneId, Mode=OneWay}" SelectedPointIds="{Binding SelectedPointIds, Mode=OneWay}" ShowAttachedPoints="{Binding ShowAttachedPoints, Mode=OneWay}" WireFrame="{Binding MeshPoints, Mode=OneWay}" Bones="{Binding Skeleton.Root}"  />
                <c:Viewport2D MouseWheel="viewport2D_MouseWheel" MouseDown="viewport2D_MouseDown" MouseMove="viewport2D_MouseMove" MouseUp="viewport2D_MouseUp" Grid.Column="2" Grid.Row="0" x:Name="viewport2DTopRightPose" Background="Silver" CameraPosition="0,1,3" CameraOrientation="Left" CameraWidth="25" MinimalUnitsBetweenGridLines="8" MinorGridSize="0.2" MajorGridSize="1.0" MinorGridColor="#33000000" MajorGridColor="#55000000" AxisColor="Red" SelectedBone="{Binding SelectedBoneId, Mode=OneWay}" SelectedPointIds="{Binding SelectedPointIds, Mode=OneWay}" ShowAttachedPoints="{Binding ShowAttachedPoints, Mode=OneWay}" WireFrame="{Binding MeshPoints, Mode=OneWay}" Bones="{Binding Skeleton.Root}" />
                <c:Viewport2D MouseWheel="viewport2D_MouseWheel" MouseDown="viewport2D_MouseDown" MouseMove="viewport2D_MouseMove" MouseUp="viewport2D_MouseUp" Grid.Column="0" Grid.Row="2" x:Name="viewport2DBottomLeftPose" Background="Silver" CameraPosition="1,0,3" CameraOrientation="Top" CameraWidth="25" MinimalUnitsBetweenGridLines="8" MinorGridSize="0.2" MajorGridSize="1.0" MinorGridColor="#33000000" MajorGridColor="#55000000" AxisColor="Red" SelectedBone="{Binding SelectedBoneId, Mode=OneWay}" SelectedPointIds="{Binding SelectedPointIds, Mode=OneWay}" ShowAttachedPoints="{Binding ShowAttachedPoints, Mode=OneWay}" WireFrame="{Binding MeshPoints, Mode=OneWay}" Bones="{Binding Skeleton.Root}" />
                <Grid Grid.Column="2" Grid.Row="2" Background="Black">
                    <Viewport3D x:Name="viewport3DPose" ClipToBounds="True">
                        <Viewport3D.Camera>
                            <PerspectiveCamera
						Position="0,0,50"
						LookDirection="0,0,-1"
						UpDirection="0,1,0"
						NearPlaneDistance="0.1"
						FarPlaneDistance="100"
						FieldOfView="60">
                                <PerspectiveCamera.Transform>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D Axis="0,1,0" Angle="45"/>
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                </PerspectiveCamera.Transform>
                            </PerspectiveCamera>
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <Model3DGroup >
                                    <AmbientLight Color="#FF333333" />
                                    <PointLight Color="White" Position="30,30,30" Range="50"/>
                                    <Model3DGroup>
                                        <GeometryModel3D x:Name="displayModelPose" />
                                    </Model3DGroup>
                                </Model3DGroup>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
                </Grid>
            </Grid>
			<Grid Grid.Column="4" Background="{DynamicResource BaseBrush}">
				<Grid.RowDefinitions>
					<RowDefinition Height="auto"/>
					<RowDefinition Height="auto"/>
					<RowDefinition Height="*"/>
					<RowDefinition Height="auto"/>
				</Grid.RowDefinitions>
				<Grid Background="Black">
					<Image Stretch="None" HorizontalAlignment="Left" Source="/Styles/MiniBanner.png"/>
				</Grid>
				<GroupBox Header="Skeleton" Grid.Row="1" Margin="5,5,5,0">
					<c:SkeletonTreeView x:Name="skeletonTreeView" TreeStyle="{StaticResource SkeletonTreeViewStyle}" TreeNodeStyle="{StaticResource SkeletonTreeNodeStyle}" Items="{Binding Skeleton}" SelectedItemChanged="skeletonTreeView_SelectedItemChanged" Margin="5,5,5,0">
						<c:SkeletonTreeView.Resources>
							<DataTemplate DataType="{x:Type sac:Bone}">
								<TextBlock  Text="{Binding Path=Name}"/>
							</DataTemplate>
						</c:SkeletonTreeView.Resources>
					</c:SkeletonTreeView>
				</GroupBox>
				<TabControl x:Name="TaskTab" Grid.Row="2" SelectionChanged="TaskTab_SelectionChanged" Margin="0,5,0,0" Background="{StaticResource BaseBrush}" >
					<TabItem x:Name="PoseTaskTab" Header="Pose" Background="{StaticResource BaseBrush}" >
						<ScrollViewer CanContentScroll="False" VerticalScrollBarVisibility="Auto">
							<StackPanel>
								<GroupBox  Header="Edit">
									<Grid DataContext="{Binding ElementName=skeletonTreeView, Path=SelectedItem}" x:Name="EditBonePanel">
										<Grid.RowDefinitions>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
										</Grid.RowDefinitions>
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="auto"/>
											<ColumnDefinition />
											<ColumnDefinition Width="auto"/>
										</Grid.ColumnDefinitions>
										<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="0,5,5,0">Name:</TextBlock>
										<TextBox x:Name="BoneNameTextBox" Grid.Row="0" Grid.Column="1" Margin="0,5,5,0" Text="{Binding Name}"/>
										<Button x:Name="RenameBoneButton" Grid.Row="0" Grid.Column="2" Margin="0,5,0,0" Click="RenameBoneButton_Click">Rename</Button>
										<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="0,5,5,0">Size:</TextBlock>
										<TextBox x:Name="BoneSizeTextBox" Grid.Row="1" Grid.Column="1" Margin="0,5,5,0" Text="{Binding Size}"/>
										<Button Grid.Row="1" Grid.Column="2" Margin="0,5,0,0" Click="SetBoneSizeButton_Click">Set</Button>
										<ToggleButton x:Name="MoveBoneButton"  Grid.Row="2" Margin="0,5,5,0" Click="MoveBoneButton_Click">Move</ToggleButton>
										<ToggleButton x:Name="AddBoneButton" Grid.Row="2" Grid.Column="1" Margin="0,5,5,0" Click="AddBoneButton_Click">Add Bones</ToggleButton>
										<Button x:Name="DeleteBoneButton" Grid.Row="2" Grid.Column="2" Margin="0,5,0,0">Delete</Button>
									</Grid>
								</GroupBox>
								<GroupBox x:Name="PointsBonePanel" Header="Points" Margin="0,5,0,0">
									<Grid HorizontalAlignment="Stretch">
										<Grid.RowDefinitions>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
											<RowDefinition Height="auto"/>
										</Grid.RowDefinitions>
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="auto"/>
											<ColumnDefinition Width="*"/>
											<ColumnDefinition Width="auto"/>
										</Grid.ColumnDefinitions>
										<ToggleButton x:Name="ShowAttachedPointsButton" Grid.Row="0" Grid.ColumnSpan="3" Click="ShowAttachedPointsButton_Click" Margin="0,5,0,0">Show Attached Points</ToggleButton>
										<ToggleButton x:Name="SelectPointsButton" Grid.Row="1" Grid.ColumnSpan="3" Margin="0,5,0,0" Click="SelectPointsButton_Click">Select Points</ToggleButton>
										<ToggleButton x:Name="DeselectPointsButton" Grid.Row="2" Grid.ColumnSpan="3" Margin="0,5,0,0" Click="DeselectPointsButton_Click">Deselect Points</ToggleButton>
										<Button x:Name="AttachPointsButton" Grid.Row="3" Grid.ColumnSpan="3" Margin="0,5,0,0" Click="AttachPointsButton_Click">Attach Points</Button>
										<Button x:Name="DetachPointsButton" Grid.Row="4" Grid.ColumnSpan="3" Margin="0,5,0,0" Click="DetachPointsButton_Click">Detach Points</Button>
										<TextBox Grid.Row="5" Width="30" TextAlignment="Center" Text="{Binding ElementName=WeightSlider, Path=Value, UpdateSourceTrigger=PropertyChanged}" Margin="0,5,5,0" Background="{DynamicResource BrightBrush}"/>
										<Grid Grid.Column="1" Grid.Row="5"  Margin="0,5,5,0">
											<Rectangle RadiusX="3" RadiusY="6">
												<Rectangle.Fill>
													<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
														<GradientStop Offset="0" Color="Green"/>
														<GradientStop Offset="1" Color="Red"/>
													</LinearGradientBrush>
												</Rectangle.Fill>
												<Rectangle.RenderTransform>
													<ScaleTransform ScaleX="1" ScaleY="0.5"/>
												</Rectangle.RenderTransform>
											</Rectangle>
											<Slider x:Name="WeightSlider" TickFrequency="1" IsSnapToTickEnabled="True"  Minimum="0" Maximum="100"/>
										</Grid>

										<Button x:Name="SetWeightButton" Grid.Row="5" Grid.Column="2" Margin="0,5,0,0" Click="SetWeightButton_Click">Set Weight</Button>
									</Grid>
								</GroupBox>
							</StackPanel>
						</ScrollViewer>
					</TabItem>
					<TabItem x:Name="AnimateTaskTab" Header="Animate" Background="{StaticResource BaseBrush}">
						<StackPanel>
							<GroupBox Header="Animations">
								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="auto"/>
										<ColumnDefinition Width="*" />
									</Grid.ColumnDefinitions>
									<Grid.RowDefinitions>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
									</Grid.RowDefinitions>
									<TextBlock Grid.Row="0" Grid.Column="0" Text="Current:" VerticalAlignment="Center" Margin="0,5,5,0"/>
									<ComboBox x:Name="animationsComboBox" Grid.Row="0" Grid.Column="1">
										<ComboBox.Resources>
											<DataTemplate DataType="{x:Type sac:BoneAnimation}">
												<TextBlock Text="{Binding Name}"/>
											</DataTemplate>
										</ComboBox.Resources>
									</ComboBox>
									<Button x:Name="NewAnimationButton" Click="NewAnimationButton_Click" Grid.Row="1" Grid.Column="0" Margin="0,5,5,0">New</Button>
								</Grid> 
							</GroupBox>
							<GroupBox Header="Animation" Margin="0,5,0,0">
								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="auto"/>
										<ColumnDefinition Width="*" />
										<ColumnDefinition Width="auto"/>
									</Grid.ColumnDefinitions>
									<Grid.RowDefinitions>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
									</Grid.RowDefinitions>
									<TextBlock Grid.Row="0" Grid.Column="0" Text="Name:" VerticalAlignment="Center" Margin="0,5,5,0"/>
									<TextBox Grid.Row="0" Grid.Column="1" Margin="0,5,5,0"/>
									<Button Grid.Row="0" Grid.Column="2" Margin="0,5,0,0">Rename</Button>
								</Grid>
							</GroupBox>
							<GroupBox Header="Frame" Margin="0,5,0,0">
								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="auto"/>
										<ColumnDefinition Width="*" />
										<ColumnDefinition Width="auto"/>
									</Grid.ColumnDefinitions>
									<Grid.RowDefinitions>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
										<RowDefinition Height="auto"/>
									</Grid.RowDefinitions>
								</Grid>
							</GroupBox>
							
						</StackPanel>
					</TabItem>
				</TabControl>
				<Grid Grid.Row="3" Background="{DynamicResource BaseVerticalGradient}">
					<GroupBox Header="Help" Margin="5">
						<TextBlock x:Name="HelpTextBlock" TextWrapping="Wrap"/>
			</GroupBox>
				</Grid>
			</Grid>
			
			<StatusBar Grid.Row="4" Grid.ColumnSpan="6" Background="{StaticResource BaseVerticalGradient}">
				<StatusBarItem x:Name="StatusBarStatus" HorizontalAlignment="Left">Ready</StatusBarItem>
				<StatusBarItem x:Name="StatusBarCurrentDocument" HorizontalAlignment="Left"></StatusBarItem>
			</StatusBar>
		</Grid>
	</Grid>
</Window>
